<?php

/**
 * Created by PhpStorm.
 * User: wukent
 * Date: 2017/9/22
 * Time: 下午1:53
 */
class UploadAction extends ApiAction
{


    public function doupload(){

        import('ORG.Net.UploadFile');
        $upload = new UploadFile();// 实例化上传类
        $upload->maxSize  = 3145728 ;// 设置附件上传大小
        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->savePath =  './Attachment/Merchant/';// 设置附件上传目录

        $upload->autoSub =  true;//
        $upload->subType = 'date';

        $upload->thumb = true;
        $upload->thumbType = 0;
        $upload->thumbMaxWidth = 800;
        $upload->thumbMaxHeight = 800;


        if(!$upload->upload()) {// 上传错误提示错误信息
            $this->error($upload->getErrorMsg());
        }else{// 上传成功 获取上传文件信息
            $info =  $upload->getUploadFileInfo();
            $thumbinfo = explode('/', $info[0]['savename']);
            $photo_path = '/merchant'.substr($info[0]['savepath'].$thumbinfo[0].'/thumb_'.$thumbinfo[1],1);

            $this->rest($photo_path,1);
        }


    }

}